﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;

namespace Workflows.JobDispatcherService
{
    public partial class Service1 : ServiceBase
    {
        private Workflows.Components.JobDispatcherService jobService;

        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            this.StartJobDispatcherService();
        }

        protected override void OnStop()
        {
            this.StopJobDispatcherService();
        }

        private void StartJobDispatcherService()
        {
            if (this.jobService != null)
            {
                if (!this.jobService.IsActive)
                {
                    this.jobService.Start();
                }
            }
            else
            {
                this.jobService = new Workflows.Components.JobDispatcherService();
                this.jobService.Start();
            }
        }

        private void StopJobDispatcherService()
        {
            if (this.jobService != null)
            {
                if (this.jobService.IsActive)
                {
                    this.jobService.Stop();
                }
            }
        }
    }
}
